package com.changyinBus.system.service.impl;

import com.changyinBus.common.core.domain.entity.SysArticle;
import com.changyinBus.system.service.IRaffleService;
import com.changyinBus.system.service.ISysArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Random;

@Service
public class RaffleServiceImpl implements IRaffleService {


    @Override
    public double lottery(SysArticle article) {

        Random random = new Random();
        double randomValue = random.nextDouble(); // 生成0.0-1.0之间的随机数
        double winRate = Double.parseDouble(article.getTitle());
        // 如果随机数小于中奖概率，则中奖
        if(randomValue < winRate){
            String[] prizes = article.getIntro().split(",");
            random = new Random();
            int prizeNum = random.nextInt(prizes.length);
            return Double.parseDouble(prizes[prizeNum]);
        }
        return 0D;
    }
}
